﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model;

namespace PMS.Web
{
    public partial class AddMenu : System.Web.UI.Page
    {
        BLL.PMS_RoleListBLL bll = new BLL.PMS_RoleListBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string roleID = Request["roleID"];
                string parentID = Request["parentID"];
                if (!string.IsNullOrEmpty(roleID) && roleID != "0")
                {
                    PMS_RoleList model = bll.GetModel(Convert.ToInt32(roleID));
                    txt_RoleText.Text = model.roleText;
                    txt_Description.Text = model.roleDescription;
                    hid_RoleID.Value = roleID;
                }
                if (!string.IsNullOrEmpty(parentID) && parentID != "0")
                {
                    hid_parentID.Value = parentID;
                }
            }
        }

        protected void btn_Add_Click(object sender, EventArgs e)
        {
            PMS_RoleList model = new PMS_RoleList();
            model.roleID = Convert.ToInt32(hid_RoleID.Value);
            model.parentID = Convert.ToInt32(hid_parentID.Value);
            model.roleDescription = txt_Description.Text;
            model.roleText = txt_RoleText.Text;
            if (model.roleID <= 0 && bll.Exite(model.roleText))
            {
                this.ClientScript.RegisterStartupScript(GetType(), "msg", "<script>alert('已存在');</script>");
                return;
            }
            if (bll.AddUpdate(model))
            {
                PageComm.GetCacheListLoad();
                this.ClientScript.RegisterStartupScript(GetType(), "msg", "<script>closeWin();</script>");
            }
        }
    }
}